<?php

//登录检测
function check_login(){
    if(session('passid')){
        return session('passid');
    }else{
        return false;
    }
}

//权限检测
function check_auth(){
    $auth=new \Think\Auth();
    $rule_name=MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
    $result=$auth->check($rule_name,session('id'));
    if($result){
        return $result;
    }else{
        return false;
    }
}

//获取客户端IP地址
function getClientIP(){
    global $ip;  
    if (getenv("HTTP_CLIENT_IP"))  
        $ip = getenv("HTTP_CLIENT_IP");  
    else if(getenv("HTTP_X_FORWARDED_FOR"))  
        $ip = getenv("HTTP_X_FORWARDED_FOR");  
    else if(getenv("REMOTE_ADDR"))  
        $ip = getenv("REMOTE_ADDR");  
    else $ip = "Unknow";  
    return $ip;
}



